<?php
define('NO_NEED_LOGIN_CHECK',true);
include('init.php');
$GLOBALS['errorMessage'] = '';
$act = isset($_REQUEST['act'])?$_REQUEST['act']:'';
switch($act)
{
	case 'login':
		$accountName = $_REQUEST['accountName'];
		$password = $_REQUEST['password'];
		$db = AppMain::getDbDriver();
		$rows = $db->selectWhere(DB_TABLE_NAME_ACCOUNT, 
                              new SimpleWhereClause(DBC_ACCOUNT_NAME, '=', $accountName));
    	if(count($rows) > 0)
    	{
    		if($rows[0][DBC_ACCOUNT_PASSWORD] == $password)
    		{
    			//redirect to index page
    			SessionUtil::setVar(SESSION_KEY_LOGIN_NAME,$accountName);
    			SessionUtil::setVar(SESSION_KEY_LOGIN_ID,$rows[0][DBC_ACCOUNT_ID]);
    			header('location:index.php');
    			exit();
    		}else{
    			$GLOBALS['errorMessage'] = 'Account name or password not correct';
    		}
    	}else{
    	
        	$GLOBALS['errorMessage'] = 'Account name or password not correct';
        }
	break;
}
?>
<?php include 'header.php' ?>
<div class="logindiv">
<?php if(strlen($GLOBALS['errorMessage']) > 0):?>
<div class="error_message">
	<?php echo $GLOBALS['errorMessage'];?>
</div>
<?php endif;?>
<form method="post">
<input type="hidden" name="act" value="login"/>
<label>Account Name</label>
<input name="accountName"/>
<label>Password</label>
<input type="password" name="password"/>
<input type="submit" value="Login" class="button"/>
</form>
</div>
<?php include 'footer.php' ?>